package 常用类.Array类.map.treeMap;

import 常用类.Array类.set.User;

import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

/**
 *TreeMap是一个可排序的Map集合,要求其中存放的数据的key是可排序的
 *TreeMap是根据key进行排序，与value无关
 */
public class TreeMapDome {
    public static void main(String[] args) {
        TreeMap<User,Integer> map=new TreeMap<User,Integer>(new Comparator<User>() {
            @Override
            public int compare(User user1, User user2) {
                return user1.getUserId()- user2.getUserId();
            }
        });
        map.put(new User(1,"admin1"),20);
        map.put(new User(6,"admin2"),10);
        map.put(new User(2,"admin3"),25);

        for (Map.Entry<User,Integer> entry:map.entrySet()){
            System.out.println(entry);
        }
    }
}
